﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Security.Cryptography;

namespace common {
	public class connection {
		public static string SqlConnStr = "data source=192.168.0.67;Database=DataBuffer;Uid=sa;Pwd=cccccc;";

		public static SqlConnection conn = new SqlConnection(SqlConnStr);

		//查询数据库，返回数据表
		public static DataTable BindTable(string sqlstr) {
			try {
				using (var SqlConn = new SqlConnection(SqlConnStr)) {
					SqlConn.Open();
					var SqlCmd = SqlConn.CreateCommand();
					SqlCmd.CommandText = sqlstr;
					SqlCmd.CommandTimeout = 0;
					using (var cmd = new SqlDataAdapter(SqlCmd)) {
						var dt = new DataTable();
						cmd.Fill(dt);
						SqlConn.Close();
						return dt;
					}
				}
			} catch (Exception) {
				var dt = new DataTable();
				conn.Close();
				return dt;
			}
		}
	}
}
